package sk.xorty.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import sk.xorty.domain.Message;
import sk.xorty.service.MessageBoardService;

@Controller
@RequestMapping("/messageDelete*")
public class MessageDeleteController {

    @Autowired
    MessageBoardService service;

    @RequestMapping(method = RequestMethod.GET)
    public String messageDelete(@RequestParam(required = true,
            value = "messageId") Long messageId, Model model) {
        Message message = service.findById(messageId);
        service.deleteMessage(message);
        model.addAttribute("messages", service.listMessages());

        return "redirect:messageList";
    }
}
